#include "myWindow.h"

// constructor & destructor
myWindow::myWindow(){}
myWindow::~myWindow(){
	DestroyWindow(hWnd);
	UnregisterClass(L"myWndClass", hInst);
}

// a MUST function to create window
//  hI - application instance
//	title - window title
//	fullscreen - do we want fullscreen enabled window?
//	w,h - width & height of the window
bool myWindow::myCreateWindow(HINSTANCE hI, LPCWSTR title, bool fullscreen, int w, int h){
	DWORD style;
	
	// setting the necessary flags for (not)fullscreen mode
	if (fullscreen) {
		style = WS_EX_TOPMOST | WS_POPUP;
	}else{
		style = WS_OVERLAPPEDWINDOW;
	}
	// zeroing out whole structure
	ZeroMemory(&wc, sizeof(wc));

	wc.cbSize = sizeof (WNDCLASSEX);			// setting the structure size to ... its size :p
	wc.hbrBackground = (HBRUSH) COLOR_WINDOW;	// flushing the window background with default color
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);	// setting the cursor to Arrow
	wc.hInstance = hI;							// assigning application instance
	wc.lpszClassName = L"myWndClass";			// defining the custom window class
	wc.lpfnWndProc = (WNDPROC) myWndProc;		// assigning the WindowProcedure
	wc.style = CS_HREDRAW | CS_VREDRAW;			// setting the default window style

	RegisterClassEx(&wc);	// register window class

	// let us create the window now!
	hWnd = CreateWindowEx(NULL, L"myWndClass", title, style, 50, 50, w, h, NULL, NULL, hI, NULL);

	// if we succeded creating window let's remember application instance, else -> return false
	if (hWnd){ 
		hInst = hI;
	}else{
		return false;
	}

	// let the window appear on the screen!
	ShowWindow(hWnd, SW_NORMAL);
	
	return true;
}

// the custom window procedure
LRESULT CALLBACK myWindow::myWndProc(HWND hW, UINT msg, WPARAM wParam, LPARAM lParam){
	switch (msg){
		case WM_DESTROY:
			{
				PostQuitMessage(0);
				return 0;
			}
	}
	// take care of the rest window messages
	return DefWindowProc(hW, msg, wParam, lParam);
}